import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index.vue'

Vue.use(VueRouter)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  // {
  //   path: '/',
  //   name: 'Home',
  //   component: () => import( '../views/home/index.vue')
  // },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
        path: 'home',
        component: () => import('@/views/home/index.vue'),
        name: 'home',
        meta: {
          needLogin: true
        }
      },
      {
        path: 'financial',
        component: () => import('@/views/financial/index.vue'),
        name: 'financial',
        meta: {
          needLogin: true
        }
      },
      {
        path: 'roles',
        component: () => import('@/views/roles/index.vue'),
        name: 'roles',
      },
      {
        path: 'detail',
        component: () => import('@/views/detail/index.vue'),
        name: 'detail',
      },
      {
        path: 'job',
        name: 'job',
        component: () => import('@/views/job/list.vue'),
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/list.vue'),
      },
      {
        path: 'dept',
        name: 'dept',
        component: () => import('@/views/dept/index.vue'),
      },
      // 业绩统计
      {
        path: 'result',
        name: 'result',
        component: () => import('@/views/result/index.vue'),
      },
      // 加盟商管理
      {
        path: 'franchisee',
        name: 'franchisee',
        component: () => import('@/views/franchisee/index.vue'),
      },
      // 加盟商余额
      {
        path: 'franchisee_balance',
        name: 'franchisee_balance',
        component: () => import('@/views/franchisee/money/index.vue'),
      },
      // 加盟商详情
      {
        path: 'franchisee_detail',
        name: 'franchisee_detail',
        component: () => import('@/views/franchisee/detail/index.vue'),
      },
      // 加盟商充值记录
      {
        path: 'charge_log',
        name: 'charge_log',
        component: () => import('@/views/franchisee/chargeLog/index.vue'),
      },
      // 加盟商消费记录
      {
        path: 'consume_log',
        name: 'consume_log',
        component: () => import('@/views/franchisee/consumeLog/index.vue'),
      },
      {
        path: 'visit_form',
        name: 'visit_form',
        component: () => import('@/views/franchisee/visit/index.vue'),
      },
      {
        path: 'visit_log',
        name: 'visit_log',
        component: () => import('@/views/franchisee/visit/VisitLog.vue'),
      },
      // 加盟车管理
      {
        path: 'car',
        name: 'car',
        component: () => import('@/views/car/index.vue'),
      },
      // 加盟车流水
      {
        path: 'money_car',
        name: 'money_car',
        component: ()=> import('@/views/result/car.vue')
      },
      {
        path: 'money_franchisee',
        name: 'money_franchisee',
        component: ()=> import('@/views/result/franchisee.vue')
      }

    ]
  }
]

const router = new VueRouter({
  routes
})

export default router